package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import service.service_search.Service_Search;
import tools.InterfaceDataIceList;
import tools.InterfaceForResultSetToList;
import tools.PageBeanPlus;
import view.ViewOc_Data_Ben;
import view.ViewOc_Data_Ice;
import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_boat_ben.EntityBeanOc_Boat_Ben;
import entitybean.oc_boat_ice.EntityBeanOc_Boat_Ice;
import entitybean.oc_company_info.EntityBeanOc_Company_Info;
import entitybean.oc_date_ben.EnitityBeanOc_Date_Ben;
import entitybean.oc_date_ice.EnitityBeanOc_Date_Ice;
import entitybean.oc_depthlist_ben.EntityBeanOc_Depthlist_Ben;
import entitybean.oc_depthlist_ice.EntityBeanOc_Depthlist_Ice;
import entitybean.oc_property_ben.EntityBean_Oc_Property_Ben;
import entitybean.oc_property_ice.EntityBean_Oc_Property_Ice;
import entitybean.oc_property_tools_ben.EntityBean_Oc_Property_Tools_Ben;
import entitybean.oc_property_tools_ice.EntityBean_Oc_Property_Tools_Ice;
import entitybean.oc_station_ben.EntityBeanOc_Station_Ben;
import entitybean.oc_station_ice.EntityBeanOc_Station_Ice;
import entitybean.oc_voyage_ben.EnitityBeanOc_Voyage_Ben;
import entitybean.oc_voyage_ice.EnitityBeanOc_Voyage_Ice;
import form.DataBenForm;
import form.DataIceForm;

public class Action_Oc_Data_Ice extends DispatchAction{
	private Service_Admin service_admin;
    private Service_Public service_public;
 	private Service_Search service_search;
	public ActionForward admin_init_oc_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataIceForm boatIceForm = (DataIceForm) form;

		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_ICE.DEPTH FROM OC_DEPTHLIST_ICE WHERE OC_DEPLIST_ID=OC_DEPTHLIST_ICE.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_ICE.STATION_NAME FROM OC_STATION_ICE WHERE OC_STATION_ID=OC_STATION_ICE.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_ICE.VOYAGE_NAME FROM OC_VOYAGE_ICE WHERE OC_VOYAGE_ID=OC_VOYAGE_ICE.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_ICE.PROPERTY_NAME FROM OC_PROPERTY_ICE WHERE OC_PROPERTY_ID=OC_PROPERTY_ICE.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_ICE.TOOLS_NAME FROM OC_PROPERTY_TOOLS_ICE WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_ICE.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_ICE.OC_BOATNAME FROM OC_BOAT_ICE WHERE (SELECT OC_VOYAGE_ICE.BOATID FROM OC_VOYAGE_ICE WHERE ID=OC_VOYAGE_ID)=OC_BOAT_ICE.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_ICE where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(boatIceForm.getRowcountperpage()), Integer
						.valueOf(boatIceForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Ice> list = interfaceforresultsettolist
				.ViewOc_Data_Ice(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", boatIceForm);
		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

	public ActionForward admin_add_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<EntityBean_Oc_Property_Ice> property_list = service_search.Find_EntityBean_Oc_Property_Ice();

		List<EntityBeanOc_Boat_Ice> boat_list = service_search.Find_EntityBeanOc_Boat_Ice();

		List<EntityBeanOc_Depthlist_Ice> depthlist = service_search.Find_EntityBeanOc_Depthlist_Ice();

		request.setAttribute("depthlist", depthlist);
		request.setAttribute("boat_list", boat_list);
		request.setAttribute("property_list", property_list);

		return mapping.findForward("success");
	}

	public ActionForward admin_insert_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataIceForm goodform = (DataIceForm) form;
		Integer deplist_id=goodform.getOc_deplist_id();
		Integer property_id=goodform.getOc_property_id();
		Integer oc_property_tools_id=goodform.getOc_property_tools_id();
		Integer oc_station_id=goodform.getOc_station_id();
		Integer oc_voyage_id=goodform.getOc_voyage_id();
		Double value_key=goodform.getValue_key();
		EnitityBeanOc_Date_Ice link=new EnitityBeanOc_Date_Ice();
        link.setOc_deplist_id(deplist_id);
        link.setOc_property_id(property_id);
        link.setOc_property_tools_id(oc_property_tools_id);
        link.setOc_station_id(oc_station_id);
        link.setOc_voyage_id(oc_voyage_id);
        link.setValue_key(value_key);
        link.setOc_xls_upload(0);
		link.setDel("OFF");
		Integer i=0;
		EntityBeanL_Sequence entity=new EntityBeanL_Sequence();
		entity=this.service_public.Find_L_Sequence_By_seq_Name("SEQ_OC_DATA_ICE");
		i=entity.getSeq_Value()+1;
		entity.setSeq_Value(i);
		link.setId(i);
		this.service_public.Update_L_Sequence(entity);
		this.service_search.Insert_Oc_Data_Ice(link);
		System.out.println("初始化新闻模块");
		// 封装新闻查询的数据及表单
		DataIceForm dataform = (DataIceForm) form;
		dataform.setCurrentpage("1");
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_ICE.DEPTH FROM OC_DEPTHLIST_ICE WHERE OC_DEPLIST_ID=OC_DEPTHLIST_ICE.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_ICE.STATION_NAME FROM OC_STATION_ICE WHERE OC_STATION_ID=OC_STATION_ICE.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_ICE.VOYAGE_NAME FROM OC_VOYAGE_ICE WHERE OC_VOYAGE_ID=OC_VOYAGE_ICE.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_ICE.PROPERTY_NAME FROM OC_PROPERTY_ICE WHERE OC_PROPERTY_ID=OC_PROPERTY_ICE.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_ICE.TOOLS_NAME FROM OC_PROPERTY_TOOLS_ICE WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_ICE.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_ICE.OC_BOATNAME FROM OC_BOAT_ICE WHERE (SELECT OC_VOYAGE_ICE.BOATID FROM OC_VOYAGE_ICE WHERE ID=OC_VOYAGE_ID)=OC_BOAT_ICE.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_ICE where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(dataform.getRowcountperpage()), Integer
						.valueOf(dataform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Ice> list = interfaceforresultsettolist
				.ViewOc_Data_Ice(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", dataform);
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataIceForm boatIceForm = (DataIceForm) form;
		String id = boatIceForm.getId();
		id = this.cut_tail(id);
		this.service_search.Delete_Oc_Data_Ice(id);

		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_ICE.DEPTH FROM OC_DEPTHLIST_ICE WHERE OC_DEPLIST_ID=OC_DEPTHLIST_ICE.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_ICE.STATION_NAME FROM OC_STATION_ICE WHERE OC_STATION_ID=OC_STATION_ICE.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_ICE.VOYAGE_NAME FROM OC_VOYAGE_ICE WHERE OC_VOYAGE_ID=OC_VOYAGE_ICE.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_ICE.PROPERTY_NAME FROM OC_PROPERTY_ICE WHERE OC_PROPERTY_ID=OC_PROPERTY_ICE.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_ICE.TOOLS_NAME FROM OC_PROPERTY_TOOLS_ICE WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_ICE.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_ICE.OC_BOATNAME FROM OC_BOAT_ICE WHERE (SELECT OC_VOYAGE_ICE.BOATID FROM OC_VOYAGE_ICE WHERE ID=OC_VOYAGE_ID)=OC_BOAT_ICE.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_ICE where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(boatIceForm.getRowcountperpage()), Integer
						.valueOf(boatIceForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Ice> list = interfaceforresultsettolist
				.ViewOc_Data_Ice(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", boatIceForm);
		return mapping.findForward("success");
	}
	public ActionForward admin_update_init_oc_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataIceForm boatIceForm = (DataIceForm) form;
		String id=boatIceForm.getId();
		EnitityBeanOc_Date_Ice e=this.service_search.Find_EnitityBeanOc_Date_Ice(Integer.valueOf(id));
		List<EntityBeanOc_Boat_Ice> boat_list = this.service_search.Find_EntityBeanOc_Boat_Ice();
		List<EntityBean_Oc_Property_Ice> property_list = this.service_search.Find_EntityBean_Oc_Property_Ice();
		List<EntityBeanOc_Depthlist_Ice> depthlist = this.service_search.Find_EntityBeanOc_Depthlist_Ice();
		Integer boat_id = this.service_search.Find_EnitityBeanOc_Voyage_Ice(e.getOc_voyage_id()).getBoatid();
		List<EnitityBeanOc_Voyage_Ice> voyage_list = this.service_search.Find_Oc_Voyage_Ice_By_boatid(boat_id);
		List<EntityBeanOc_Station_Ice>  station_list = this.service_search.Find_Oc_Station_Ice_by_oc_voyage_id(e.getOc_voyage_id());
		List<EntityBean_Oc_Property_Tools_Ice> property_tool_list = this.service_search.Find_EntityBean_Oc_Property_Tools_Ice_by_property_id(e
						.getOc_property_id());

		request.setAttribute("voyage_list", voyage_list);
		request.setAttribute("station_list", station_list);
		request.setAttribute("property_tool_list", property_tool_list);
		request.setAttribute("depthlist", depthlist);
		request.setAttribute("boat_list", boat_list);
		request.setAttribute("property_list", property_list);
		request.setAttribute("boat_id", boat_id);
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}
	public ActionForward admin_update_oc_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataIceForm goodform = (DataIceForm) form;
		Integer deplist_id=goodform.getOc_deplist_id();
		Integer Oc_property_id=goodform.getOc_property_id();
		Integer oc_property_tools_id=goodform.getOc_property_tools_id();
		Integer oc_station_id=goodform.getOc_station_id();
		Integer oc_voyage_id=goodform.getOc_voyage_id();
		Double value_key=goodform.getValue_key();
		String id=goodform.getId();
		EnitityBeanOc_Date_Ice link=new EnitityBeanOc_Date_Ice();
        link.setOc_deplist_id(deplist_id);
        link.setOc_property_id(Oc_property_id);
        link.setOc_property_tools_id(oc_property_tools_id);
        link.setOc_station_id(oc_station_id);
        link.setOc_voyage_id(oc_voyage_id);
        link.setValue_key(value_key);
		link.setDel("OFF");
		link.setOc_xls_upload(0);
		link.setId(Integer.valueOf(id));
		this.service_search.Update_Oc_Data_Ice(link);
		DataIceForm dataform = (DataIceForm) form;
		dataform.setCurrentpage("1");
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_ICE.DEPTH FROM OC_DEPTHLIST_ICE WHERE OC_DEPLIST_ID=OC_DEPTHLIST_ICE.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_ICE.STATION_NAME FROM OC_STATION_ICE WHERE OC_STATION_ID=OC_STATION_ICE.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_ICE.VOYAGE_NAME FROM OC_VOYAGE_ICE WHERE OC_VOYAGE_ID=OC_VOYAGE_ICE.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_ICE.PROPERTY_NAME FROM OC_PROPERTY_ICE WHERE OC_PROPERTY_ID=OC_PROPERTY_ICE.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_ICE.TOOLS_NAME FROM OC_PROPERTY_TOOLS_ICE WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_ICE.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_ICE.OC_BOATNAME FROM OC_BOAT_ICE WHERE (SELECT OC_VOYAGE_ICE.BOATID FROM OC_VOYAGE_ICE WHERE ID=OC_VOYAGE_ID)=OC_BOAT_ICE.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_ICE where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(dataform.getRowcountperpage()), Integer
						.valueOf(dataform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Ice> list = interfaceforresultsettolist
				.ViewOc_Data_Ice(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", dataform);
		    return mapping.findForward("success");
	}

	public ActionForward admin_search_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataIceForm boatIceForm = (DataIceForm) form;
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_ICE.DEPTH FROM OC_DEPTHLIST_ICE WHERE OC_DEPLIST_ID=OC_DEPTHLIST_ICE.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_ICE.STATION_NAME FROM OC_STATION_ICE WHERE OC_STATION_ID=OC_STATION_ICE.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_ICE.VOYAGE_NAME FROM OC_VOYAGE_ICE WHERE OC_VOYAGE_ID=OC_VOYAGE_ICE.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_ICE.PROPERTY_NAME FROM OC_PROPERTY_ICE WHERE OC_PROPERTY_ID=OC_PROPERTY_ICE.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_ICE.TOOLS_NAME FROM OC_PROPERTY_TOOLS_ICE WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_ICE.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_ICE.OC_BOATNAME FROM OC_BOAT_ICE WHERE (SELECT OC_VOYAGE_ICE.BOATID FROM OC_VOYAGE_ICE WHERE ID=OC_VOYAGE_ID)=OC_BOAT_ICE.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_ICE where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(boatIceForm.getRowcountperpage()), Integer
						.valueOf(boatIceForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Ice> list = interfaceforresultsettolist
				.ViewOc_Data_Ice(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", boatIceForm);
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}

	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin service_admin) {
		this.service_admin = service_admin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public service_public) {
		this.service_public = service_public;
	}

	public Service_Search getService_search() {
		return service_search;
	}

	public void setService_search(Service_Search service_search) {
		this.service_search = service_search;
	}
}
